package com.xhh.nphm.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhh.nphm.common.core.domain.QueryConditionVo;
import com.xhh.nphm.system.domain.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;
import org.harmony.toddler.mybatis.groovy.GroovyLangDriver;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 信件拟派工单数据库操作接口
* @author Administrator
* @description 针对表【mWfSendBack】的数据库操作Mapper
* @createDate 2022-06-08 12:19:37
* @Entity com.xhh.nphm.system.domain.MwfSendBack
*/
@Mapper
public interface MwfSendBackDao extends BaseMapper<MwfSendBack> {
    /**
     * 查询下级退回信件工单审核列表数据
     *
     * @param mwfSendBack 信件拟派工单
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic," +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName, (select wf.spareString from mMailWorkForm wf where wf.PkId=wfs.WfId) as source," +
            "convert(varchar(10),SendTime,20) sdDate,convert(varchar(10),GetTime,20) as bkDate,BackRemark,PkId as opDeal " +
            "from mWfSendBack wfs where SDeptID='304'and SendState = '40' and flagInt=1 and FKInt != 1 and " +
            "wfid in (select pkid from mMailWorkForm where PkId=WfId and sparestring!='省12345') and IsDel=0 " +
            "[[and SDeptName =#{mwf.sdeptName}]] [[and (select WorkFormNO from mMailWorkForm wf where wf.PkId=wfs.WfId) = #{workFormNo}]]")
    List<Map<String, Object>> mmReturnFlowJson(@Param("mwf") MwfSendBack mwfSendBack,@Param("workFormNo") String workFormNo);

    /**
     * 查询市级未签收列表数据
     *
     *
     * @param deptNo 登录用户部门编号
     * @param workFormNo 信件工单编号
     * @param mwfSendBack 信件拟派工单
     * @return 列表数据
     */
    @Select("select wfs.PkId as myPkVal,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString," +
            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate," +
            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId" +
            " where wfs.SBDeptID=#{sbdeptId} and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and wfs.IsDel=0 and m.IsDel=0" +
            " [[and SDeptName =#{mwf.sdeptName}]] [[and m.WorkFormNO=#{workFormNo}]]")
    List<Map<String, Object>> signNotListJson(@Param("sbdeptId")String deptNo,@Param("workFormNo") String workFormNo,@Param("mwf")MwfSendBack mwfSendBack);

    /**
     * 查询市级未签收列表数据
     *
     *
     * @param deptNo 登录用户部门编号
     * @param workFormNo 信件工单编号
     * @param mwfSendBack 信件拟派工单
     * @return 列表数据
     */
    @Select("select wfs.PkId as myPkVal,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString," +
            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate," +
            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId" +
            " where wfs.SBDeptID=#{sbdeptId} and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and dbo.frMailWFStep(WfId) &lt; 900 AND DATEDIFF(day, GETDATE(), wfs.BackLimit) > -30 and wfs.IsDel=0 and m.IsDel=0 and wfs.BackTime is null " +
            " [[and SDeptName =#{mwf.sdeptName}]] [[and m.WorkFormNO=#{workFormNo}]]")
    List<Map<String, Object>> signNotListJson_gxq(@Param("sbdeptId")String deptNo,@Param("workFormNo") String workFormNo,@Param("mwf")MwfSendBack mwfSendBack);


    /**
     * 查询待本部门回复列表数据
     *
     * @param deptNo 登录用户部门编号
     * @param workFormNo 信件工单编号
     * @param mwfSendBack 信件拟派工单
     * @return 列表数据
     */
    @Select(" select m1.PkId as myPkVal,WfId,MailPK,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,m2.WorkFormNO as myMwfNO,isUrge," +
            " m2.FromTopic as myMwfTopic,m2.FmContent as FmContent,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit," +
            " (select SortName from bSort where CodePk=str(left(m3.DCntACode,4),4)) dCntAName1, " +
            " (select SortName from bSort where CodePk=str(left(m3.DCntACode,6),6)) dCntAName2, " +
            " (select SortName from bSort where CodePk=str(left(m3.DCntACode,8),8)) dCntAName3, " +
            " SDeptName,convert(varchar(10),GetTime,20) as acDate,BackState as bkState,BackRemark as acRemark," +
            " subBackState cbackDesc,m2.SpareString as SpareString " +
            " from mWfSendBack m1 left join mMailWorkForm m2 on m1.WfId=m2.PkId left join mMailGetDeal m3 on m2.OriginFK=m3.PkId " +
            " where m1.SBDeptID = #{sbdeptId} and m1.SendState in(21,23) and m1.BackState in (0,12,22) and m1.IsDel=0 and m2.IsDel=0 " +
            "[[and m1.SDeptName =#{mwf.sdeptName}]] " +
            "[[and m2.SpareString =#{qc.spareString}]]"+
            "[[and convert(varchar(10),m1.BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),m1.BackLimit,120) &lt;= #{qc.endTime}]] " +
            "[[and m1.subBackState=#{mwf.backDesc}]] " +
//            "[[and replace(#{mwf.backDesc},'0','') = dbo.mWfNOBackDesc(WfId,#{sbdeptId})]]" +
            "[[and m2.WorkFormNO = #{workFormNo}]]")
    List<Map<String, Object>> replyWaitJson(@Param("sbdeptId")String deptNo,@Param("workFormNo") String workFormNo,@Param("mwf")MwfSendBack mwfSendBack, @Param("qc") QueryConditionVo qc);

    @Select(" select m1.PkId as myPkVal,WfId,MailPK,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,m2.WorkFormNO as myMwfNO,isUrge," +
            " m2.FromTopic as myMwfTopic,m2.FmContent as FmContent,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit," +
            " (select SortName from bSort where CodePk=str(left(m3.DCntACode,4),4)) dCntAName1, " +
            " (select SortName from bSort where CodePk=str(left(m3.DCntACode,6),6)) dCntAName2, " +
            " (select SortName from bSort where CodePk=str(left(m3.DCntACode,8),8)) dCntAName3, " +
            " SDeptName,convert(varchar(10),GetTime,20) as acDate,BackState as bkState,BackRemark as acRemark," +
            " subBackState cbackDesc,m2.SpareString as SpareString " +
            " from mWfSendBack m1 left join mMailWorkForm m2 on m1.WfId=m2.PkId left join mMailGetDeal m3 on m2.OriginFK=m3.PkId " +
            " where m1.SBDeptID = #{sbdeptId} and m1.SendState in(21,23) and m1.BackState in (0,12,22) and m1.IsDel=0 and m2.IsDel=0 and m1.isUrge=1 " +
            "[[and m1.SDeptName =#{mwf.sdeptName}]] " +
            "[[and m2.SpareString =#{qc.spareString}]]"+
            "[[and convert(varchar(10),m1.BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),m1.BackLimit,120) &lt;= #{qc.endTime}]] " +
            "[[and m1.subBackState=#{mwf.backDesc}]] " +
//            "[[and replace(#{mwf.backDesc},'0','') = dbo.mWfNOBackDesc(WfId,#{sbdeptId})]]" +
            "[[and m2.WorkFormNO = #{workFormNo}]]")
    List<Map<String, Object>> replyWaitJson1(@Param("sbdeptId")String deptNo,@Param("workFormNo") String workFormNo,@Param("mwf")MwfSendBack mwfSendBack, @Param("qc") QueryConditionVo qc);

    /**
     * 查找待本部门回复的工单数据
     *
     * @param paramMap 参数
     * @return 工单列表数据
     */
    @Select("MwfSendBackSql#replyWaitJson_jjq")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> replyWaitJson_jjq(Map paramMap);

    @Select("MwfSendBackSql#replyWaitJson_px")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> replyWaitJson_px(Map paramMap);

    /**
     * 查找待本部门回复的工单数据导出
     *
     * @param paramMap 参数
     * @return 工单列表数据
     */
    @Select("DataExportSql#replyWaitJson_jjqExport")
    @Lang(GroovyLangDriver.class)
    List<ReplyWaitMailExcel> replyWaitJson_jjqExport(Map paramMap);

    @Select("DataExportSql#replyWaitJson_pxExport")
    @Lang(GroovyLangDriver.class)
    List<ReplyWaitMailExcel> replyWaitJson_pxExport(Map paramMap);

    @Select("select * from mWfSendBack" +
            " where wfId = #{pkId} and IsDel=0")
    List<MwfSendBack> selectByWfId(String pkId);

    @Select("select PkId,WfId,SeqName,SortName,DealName,SBDeptName,SendDesc,SDeptName,convert(varchar(19),BackLimit,20) as backLimit,SUserName,convert(varchar(19),SendTime,20) as sendTime,SendState,convert(varchar(19),GetTime,20) as getTime,GetPerson,BUserName,convert(varchar(19),BackTime,20) as backTime from mWfSendBack where WfId=#{wfId} and OriLevel=1 and IsDel=0")
    List<MwfSendBack> sendDeptListJson(@Param("wfId") Integer wfId);

    /**
     * 查询信件拟派工单
     *
     * @param wfId    工单编号
     * @param sdeptId 派发部门编号
     * @return 拟派工单列表
     */
    @Select("select * from mWfSendBack where WfId= #{param1} AND SDeptId = #{param2} AND sortCode <> '21' AND sendState <> 40 AND isDel=0")
    List<MwfSendBack> ltSendBackMain(int wfId, String sdeptId);

    /**
     * 查询审核本部门回复列表数据
     *
     * @param deptId     当前登录用户部门编号
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,dbo.frMailWFNo(WfId) as myMwfNO," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SDeptName,SeqName,SortName,DealName,SBDeptName,convert(varchar(10),BackLimit,20) as bkLimit," +
            "SBDeptName,convert(varchar(10),BackTime,20) as bkDate,BackState as chgBack,dbo.frMailWFSpareStr(WfId) as SpareString from mWfSendBack " +
            "where SBDeptID=#{param1} and BackState in (10) and IsDel=0 " +
            "[[AND dbo.frMailWFNo(WfId) = #{param2}]] [[AND SDeptName =#{param3}]]")
    List<Map<String, Object>> replyChkJson(String deptId, String workFormNo, String sdeptName);

    /**
     * 查询本部门已办毕列表数据
     *
     * @param deptId     当前登录用户部门编号
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,(select FmContent from mMailWorkForm where PkId=WfId) as FmContent,SDeptName,SeqName,SBDeptName,SortName," +
            "DealName,convert(varchar(10),BackLimit,20) as bkLimit,convert(varchar(10),BackTime,20) as bkDate," +
            "BackState as chgBack,BackRemark,PkId as opDeal from mWfSendBack where SBDeptID=#{param1} " +
            "and BackState in (11,21) and IsDel=0"+
//            "and BackState in (11,21) and IsDel=0 and SendState not in(30,40) " +
            "[[AND dbo.frMailWFNo(WfId) = #{param2}]] [[AND SDeptName =#{param3}]]")
    List<Map<String, Object>> repleOverJson(String deptId, String workFormNo, String sdeptName);

    /**
     * 根据用户角色编号和部门编号 查询全区实时满意情况
     *
     * @param params 参数
     * @return List<Map>
     */
    @Select("{call psMailTotalHandleState(#{roleId,mode=IN,jdbcType=VARCHAR},#{deptId,mode=IN,jdbcType=VARCHAR})}")
    @Options(statementType = StatementType.CALLABLE)
    List<Map> psMailTotalHandleState(Map<String, String> params);

    @Select("{call psMailTotalHandleState_gxq(#{roleId,mode=IN,jdbcType=VARCHAR},#{deptId,mode=IN,jdbcType=VARCHAR})}")
    @Options(statementType = StatementType.CALLABLE)
    List<Map> psMailTotalHandleState_gxq(Map<String, String> params);

    /**
     * 查找待分发下级工单数据
     *
     * @param deptId     部门id
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 工单列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic," +
            "(select FmContent from mMailWorkForm where PkId=WfId) as FmContent," +
            "SeqName,SBDeptName,SortName,SDeptName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,convert(varchar(10),GetTime,20) as acDate,BackRemark as acDesc from mWfSendBack" +
            " where SBDeptID=#{sbdeptId} and SendState=22 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> sendWaitListJson(@Param("sbdeptId") Long deptId,@Param("workFormNo")String workFormNo,@Param("sdeptName")String sdeptName);

    @Select("select PkId as myPkVal,WfId,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic," +
            "(select FmContent from mMailWorkForm where PkId=WfId) as FmContent," +
            "SeqName,SBDeptName,SortName,SDeptName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,convert(varchar(10),GetTime,20) as acDate,BackRemark as acDesc from mWfSendBack " +
            " where SBDeptID=#{sbdeptId} and SendState=22 and IsDel=0 and dbo.frMailWFStep(WfId)>399 and dbo.frMailWFStep(WfId) &lt; 900 and DATEDIFF(day,GetDate(),BackLimit) > -60 " +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> sendWaitListJson_gxq(@Param("sbdeptId") Long deptId,@Param("workFormNo")String workFormNo,@Param("sdeptName")String sdeptName);

    /**
     * 查找上级不同意退回工单数据
     *
     * @param deptId 部门编号
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SeqName,SBDeptName,SortName,SDeptName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,SendRemark" +
            " from mWfSendBack where SBDeptID=#{sbdeptId} and SendState in(51) and dbo.frMailWFStep(WfId)>399 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> notPassListJson(@Param("sbdeptId") Long deptId,@Param("workFormNo")String workFormNo,@Param("sdeptName")String sdeptName);

    /**
     * 查找下级退回工单数据
     *
     * @param deptId     部门编号
     * @param workFormNo
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SBDeptName,SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState,BackState as chgChk" +
            " from mWfSendBack where SDeptID=#{sdeptId} and SendState=40 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> listSonBackJson(@Param("sdeptId") Long deptId,@Param("workFormNo")String workFormNo,@Param("sdeptName")String sdeptName);

    /**
     * 查找下级退回 已处理工单
     *
     * @param deptId     部门编号
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SBDeptName,SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState,BackState as chgChk,pid " +
            "from mWfSendBack where SDeptID=#{sdeptId} and SendState in(40,51) and flagInt=0 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]] " +
            "[[and dbo.frMailWFSpareStr(WfId) =#{spareString}]]")
    List<Map<String, Object>> listSonAgreeBackJson(@Param("sdeptId") Long deptId,@Param("workFormNo")String workFormNo,@Param("sdeptName")String sdeptName,@Param("spareString")String spareString);

    /**
     * 查找下级未签收工单数据
     * @param deptId 部门编号
     * @param workFormNo 工单编号
     * @param sdeptName 派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic," +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName," +
            "convert(varchar(10),SendTime,20) sdDate,SendRemark " +
            "from mWfSendBack  where SDeptID=#{deptId} and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]][[and SBDeptName=#{sdeptName}]]")
    List<Map<String, Object>> listSonSignNot(@Param("deptId") Long deptId, @Param("workFormNo") String workFormNo,@Param("sdeptName") String sdeptName);

    /**
     * 查找超出办理期限的工单数据
     *
     * @param deptId     部门编号
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,dbo.frMailWFNo(WfId) as myMwfNO," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit," +
            "SDeptName,convert(varchar(10),GetTime,20) as acDate,BackState as bkState,BackRemark as acRemark from mWfSendBack " +
            "where SBDeptID=#{deptId} and SendState in(21,23) and BackState in (0,12,22) and IsDel=0 " +
            "and DATEDIFF(day, GETDATE(), BackLimit) IN (1,0)" +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> muBlueSJson(@Param("deptId") Long deptId, @Param("workFormNo") String workFormNo,@Param("sdeptName") String sdeptName);

    /**
     * 查找未超出办理期限的工单数据
     *
     * @param deptId     部门编号
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,dbo.frMailWFNo(WfId) as myMwfNO," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit," +
            "SDeptName,convert(varchar(10),GetTime,20) as acDate,BackState as bkState,BackRemark as acRemark from mWfSendBack " +
            "where SBDeptID=#{deptId} and SendState in(21,23) and BackState in (0,12,22) and IsDel=0 and getdate() &gt; BackLimit" +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> muRedSJson(@Param("deptId") Long deptId, @Param("workFormNo") String workFormNo,@Param("sdeptName") String sdeptName);

    /**
     * 查找退回的工单数据
     *
     * @param deptId     部门编号
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic," +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName," +
            "(select k.SpareString from mMailWorkForm k where k.PkId=WfId) SpareString," +
            "convert(varchar(10),SendTime,20) sdDate,convert(varchar(10),GetTime,20) as bkDate,BackRemark from mWfSendBack " +
            "where SBDeptID=#{param1} and SendState = 40 and IsDel=0" +
            "[[and dbo.frMailWFNo(WfId) = #{param2}]] [[and SDeptName =#{param3}]]")
    List<Map<String, Object>> deptBackJson(Long deptId, String workFormNo, String sdeptName);

    /**
     * 查找本区办理量的信件工单列表
     * @param params
     * @return
     */
    @Select("select PkId as myPkVal,WfId," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SDeptName,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit," +
            "convert(varchar(10),BackTime,20) as bkDate,BackState as chgBack,BackRemark FROM mWfSendBack " +
            "WHERE SendTime BETWEEN #{startTime} AND #{endTime} AND SBDeptID = #{sbdeptId} AND BackState in (11,21) AND IsDel = 0 " +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptReplyOverListJson(HashMap<String, Object> params);

    /**
     * 查找本区 未转派的信件工单列表
     * @param params
     * @return
     */
    @Select("select PkId as myPkVal,WfId," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SeqName,SBDeptName,SortName,SDeptName," +
            "convert(varchar(10),BackLimit,20) BackLimit,convert(varchar(10),GetTime,20) as acDate,BackRemark as acDesc FROM mWfSendBack " +
            "WHERE   SBDeptID = #{sbdeptId} and SendState=22 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptSendWaitListJson(HashMap<String, Object> params);

    @Select("select PkId as myPkVal,WfId," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SeqName,SBDeptName,SortName,SDeptName," +
            "convert(varchar(10),BackLimit,20) BackLimit,convert(varchar(10),GetTime,20) as acDate,BackRemark as acDesc FROM mWfSendBack " +
            "WHERE   SBDeptID = #{sbdeptId} and SendState=22 and IsDel=0 and DATEDIFF(day, GETDATE(), BackLimit) > -30 " +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptSendWaitListJson_gxq(HashMap<String, Object> params);

    /**
     * 查找被市级拒退工单列表数据
     * @param params
     * @return
     */
    @Select("select PkId as myPkVal,WfId," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,SendRemark,SAttachPath FROM mWfSendBack " +
            "WHERE   SBDeptID = #{sbdeptId} And SendState=51 and dbo.frMailWFStep(WfId)>399 and IsDel=0" +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptNotPassListJson(HashMap<String, Object> params);

    /**
     * 查找临期工单列表
     * @param params
     * @return
     */
    @Select("select PkId as myPkVal,WfId,OriLevel,SDeptID as fmDept,SBDeptID as sbDept," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit,SDeptName,convert(varchar(10),GetTime,20) as acDate," +
            "BackState as bkState,BackRemark as acRemark,PkId as opDeal,BackDesc as backDesc from mWfSendBack " +
            "where  SBDeptID = #{sbdeptId} and SendState in(21,23) and BackState in (0,12,22) and IsDel=0 " +
            "and DATEDIFF(day, GETDATE(), BackLimit) IN (1,0)" +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> muBlueJson(HashMap<String, Object> params);

    /**
     * 查找超期工单列表
     * @param params
     * @return
     */
    @Select("select PkId as myPkVal,WfId,OriLevel,SDeptID as fmDept,SBDeptID as sbDept," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit,SDeptName,convert(varchar(10),GetTime,20) as acDate," +
            "BackState as bkState,BackRemark as acRemark,PkId as opDeal,BackDesc as backDesc from mWfSendBack " +
            "where  SBDeptID = #{sbdeptId} and SendState in(21,23) and BackState in (0,12,22) and IsDel=0 and getdate() &gt; BackLimit" +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> muRedJson(HashMap<String, Object> params);

    /**
     * 加载承办单位未签收M列表数据
     * @param params
     * @return
     */
    @Select("select PkId,WfId," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SeqName,SBDeptName,SortName,  " +
            "DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,  " +
            "SendRemark,PkId as opDeal,SAttachPath,(select mark from mMailWorkForm where PkId=WfId) as Mark  " +
            "from mWfSendBack where  SDeptID=#{sdeptId} and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]][[and SBDeptName=#{sendBack.sdeptName}]]")
    List<Map<String, Object>> SonSignNotJson(HashMap<String, Object> params);

    @Select("select PkId,WfId," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SeqName,SBDeptName,SortName,  " +
            "DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,  " +
            "SendRemark,PkId as opDeal,SAttachPath,(select mark from mMailWorkForm where PkId=WfId) as Mark  " +
            "from mWfSendBack where  SDeptID=#{sdeptId} and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and IsDel=0 and DATEDIFF(day, GETDATE(), BackLimit) > -30 " +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]][[and SBDeptName=#{sendBack.sdeptName}]]")
    List<Map<String, Object>> SonSignNotJson_gxq(HashMap<String, Object> params);

    /**
     * 加载承办单位已退M列表数据
     * @param params
     * @return
     */
    @Select("select PkId as myPkVal,WfId,SDeptID as fDNo," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SBDeptName,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState,BackState as chgChk,SAttachPath from mWfSendBack" +
            " where  SDeptID=#{sdeptId} and SendState=40 and BackState=21 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> SonAgreeBackJson(HashMap<String, Object> params);

    @Select("select PkId as myPkVal,WfId,SDeptID as fDNo," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SBDeptName,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState,BackState as chgChk,SAttachPath from mWfSendBack" +
            " where  SDeptID=#{sdeptId} and SendState=40 and BackState=21 and IsDel=0 and DATEDIFF(day, GETDATE(), BackLimit) > -30 " +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> SonAgreeBackJson_gxq(HashMap<String, Object> params);
    /**
     * 加载未签收工单列表数据
     *
     * @return 列表数据
     */
    @Select("select PkId,WfId," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SeqName,SBDeptName,SortName," +
            "DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate," +
            "SendRemark,PkId as opDeal,SAttachPath,(select mark from mMailWorkForm where PkId=WfId) as Mark " +
            "from mWfSendBack where  SBDeptID=#{sbdeptId} and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId)  = #{sendBack.myMwfNO}]][[and SBDeptName=#{sendBack.sbdeptName}]]")
    List<Map<String, Object>> rptSignNotJson(@Param("sbdeptId") String sbdeptId, @Param("sendBack") MwfSendBack sendBackEty);
    /**
     * 加载已退工单列表数据
     *
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId," +
            "dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic,"+
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit," +
            "SDeptName,convert(varchar(10),SendTime,20) sdDate,convert(varchar(10),GetTime,20) as bkDate," +
            "BackRemark from mWfSendBack where  SBDeptID=#{sbdeptId} and SendState=40 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{sendBack.myMwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptDeptBackJson(HashMap<String, Object> params);

    /**
     * 加载下级已办毕列表数据
     *
     * @param sendBackEty 查询条件
     * @param deptId      部门编号
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic," +
            "(select FmContent from mMailWorkForm where PkId=WfId) as FmContent," +
            "SBDeptName,SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState as chgBack,BackState " +
            "from mWfSendBack where SDeptID=#{param2} and SendState in (21,22,23) and BackState in (21,22) and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{param1.myMwfNO}]] [[and SDeptName =#{param1.sdeptName}]]")
    List<Map<String, Object>> listSonOverJson(MwfSendBack sendBackEty, Long deptId);

    /**
     * 加载下级已办毕 待处理列表数据
     *
     * @param sendBackEty 查询条件
     * @param deptId      部门编号
     * @return 列表数据
     */
    @Select("select m1.PkId as myPkVal,m1.PkId as pkid,WfId,MailPK,SDeptID as fDNo," +
            "m2.WorkFormNO as myMwfNO,m2.SpareString as SpareString,m2.FromTopic as myMwfTopic,m2.FmContent as FmContent," +
            "SBDeptName,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState," +
            "BackState as chgBack,BackState,pid from mWfSendBack m1 left join mMailWorkForm m2 on m1.WfId = m2.PkId " +
            "where m1.SDeptID=#{deptId} and m1.SendState in (21,22,23) and m1.BackState in (10,11) and m1.IsDel=0 and m2.IsDel = 0 " +
            "[[and m2.WorkFormNO = #{mail.myMwfNO}]] [[and m1.SBDeptName =#{mail.sbdeptName}]]")
    List<Map<String, Object>> listSonOverUntreatedJson(@Param("mail") MwfSendBack sendBackEty, @Param("deptId") String deptId);

    /**
     * 加载下级已办毕 待处理列表数据
     *
     * @param sendBackEty 查询条件
     * @param deptId      部门编号
     * @return 列表数据
     */
    @Select("select m1.PkId as myPkVal,m1.PkId as pkid,WfId,MailPK,SDeptID as fDNo," +
            "m2.WorkFormNO as myMwfNO,m2.SpareString as SpareString,m2.FromTopic as myMwfTopic,m2.FmContent as FmContent," +
            "SBDeptName,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState," +
            "BackState as chgBack,BackState,pid from mWfSendBack m1 left join mMailWorkForm m2 on m1.WfId = m2.PkId " +
            "where m1.SDeptID=#{deptId} and m1.SendState in (21,22,23) and m1.BackState in (10,11) and m1.IsDel=0 and m2.IsDel = 0 and DATEDIFF(day,GetDate(),BackLimit) > -15 " +
            "[[and m2.WorkFormNO = #{mail.myMwfNO}]] [[and m1.SBDeptName =#{mail.sbdeptName}]]")
    List<Map<String, Object>> listSonOverUntreatedJson_gxq(@Param("mail") MwfSendBack sendBackEty, @Param("deptId") String deptId);
    /**
     * 加载下级已办毕 已处理列表数据
     *
     * @param sendBackEty 查询条件
     * @param deptId      部门编号
     * @return 列表数据
     */
    @Select("select m1.PkId as myPkVal,m1.PkId as pkid,WfId,MailPK,SDeptID as fDNo," +
            "m2.WorkFormNO as myMwfNO,m2.SpareString as SpareString,m2.FromTopic as myMwfTopic,m2.FmContent as FmContent," +
            "SBDeptName,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState," +
            "BackState as chgBack,BackState,pid from mWfSendBack m1 left join mMailWorkForm m2 on m1.WfId = m2.PkId " +
            "where m1.SDeptID=#{deptId} and m1.SendState in (21,22,23) and m1.BackState in (21,22) and m1.IsDel=0 and m2.IsDel = 0 " +
            "[[and m2.WorkFormNO = #{mail.myMwfNO}]] [[and m1.SBDeptName =#{mail.sbdeptName}]]")
    List<Map<String, Object>> listSonOverTreatedJson(@Param("mail")MwfSendBack sendBackEty, @Param("deptId") String deptId);

    /**
     * 加载下级办理中列表数据
     *
     * @param qc 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SBDeptID,SBDeptName,SeqName,SDeptName,SortName,DealName,isUrge," +
            "(select FmContent from mMailWorkForm where PkId=WfId) as FmContent," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState,BackState as chgChk,pid" +
            " from mWfSendBack where SDeptID=#{qc.userDeptId} and SendState in (10,21,22,23) and BackState in (0,10,12,22) and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{qc.workFormNO}]] [[and SBDeptName = #{qc.sbDeptName}]]" +
            "[[and dbo.frMailWFSpareStr(WfId) = #{qc.spareString}]]" +
            "[[and convert(varchar(10),GetTime,120) &gt;= #{qc.signBeginTime}]] [[and convert(varchar(10),GetTime,120) &lt;= #{qc.signEndTime}]] " +
            "[[and convert(varchar(10),BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),BackLimit,120) &lt;= #{qc.endTime}]] " +
            "[[and SDeptName = #{qc.sdeptName}]]")
    List<Map<String, Object>> listSonWaitJson(@Param("qc") QueryConditionVo qc);

    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SBDeptID,SBDeptName,SeqName,SDeptName,SortName,DealName,isUrge," +
            "(select FmContent from mMailWorkForm where PkId=WfId) as FmContent," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState,BackState as chgChk,pid" +
            " from mWfSendBack where SDeptID=#{qc.userDeptId} and SendState in (10,21,22,23) and BackState in (0,10,12,22) and IsDel=0 and isUrge = 1 " +
            "[[and dbo.frMailWFNo(WfId) = #{qc.workFormNO}]] [[and SBDeptName = #{qc.sbDeptName}]]" +
            "[[and dbo.frMailWFSpareStr(WfId) = #{qc.spareString}]]" +
            "[[and convert(varchar(10),GetTime,120) &gt;= #{qc.signBeginTime}]] [[and convert(varchar(10),GetTime,120) &lt;= #{qc.signEndTime}]] " +
            "[[and convert(varchar(10),BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),BackLimit,120) &lt;= #{qc.endTime}]] " +
            "[[and SDeptName = #{qc.sdeptName}]]")
    List<Map<String, Object>> listSonWaitJson1(@Param("qc") QueryConditionVo qc);

    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SBDeptID,SBDeptName,SeqName,SDeptName,SortName,DealName,isUrge," +
            "(select FmContent from mMailWorkForm where PkId=WfId) as FmContent," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState,BackState as chgChk,pid" +
            " from mWfSendBack where SDeptID=#{qc.userDeptId} and SendState in (10,21,22,23) and BackState in (0,10,12,22) and IsDel=0 and dbo.frMailWFStep(WfId)> 399 and dbo.frMailWFStep(WfId) &lt; 900 and DATEDIFF(day,GetDate(),BackLimit) > -30 " +
            "[[and dbo.frMailWFNo(WfId) = #{qc.workFormNO}]] [[and SBDeptName = #{qc.sbDeptName}]]" +
            "[[and dbo.frMailWFSpareStr(WfId) = #{qc.spareString}]]" +
            "[[and convert(varchar(10),GetTime,120) &gt;= #{qc.signBeginTime}]] [[and convert(varchar(10),GetTime,120) &lt;= #{qc.signEndTime}]] " +
            "[[and convert(varchar(10),BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),BackLimit,120) &lt;= #{qc.endTime}]] " +
            "[[and SDeptName = #{qc.sdeptName}]]")
    List<Map<String, Object>> listSonWaitJson_gxq(@Param("qc") QueryConditionVo qc);

    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SBDeptID,SBDeptName,SeqName,SDeptName,SortName,DealName,isUrge," +
            "(select FmContent from mMailWorkForm where PkId=WfId) as FmContent," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState,BackState as chgChk,pid" +
            " from mWfSendBack where SDeptID=#{qc.userDeptId} and SendState in (10,21,22,23) and BackState in (0,10,12,22) and IsDel=0 and and dbo.frMailWFStep(WfId)> 399 and dbo.frMailWFStep(WfId) &lt; 900 and DATEDIFF(day,GetDate(),BackLimit) > -30 and isUrge = 1 " +
            "[[and dbo.frMailWFNo(WfId) = #{qc.workFormNO}]] [[and SBDeptName = #{qc.sbDeptName}]]" +
            "[[and dbo.frMailWFSpareStr(WfId) = #{qc.spareString}]]" +
            "[[and convert(varchar(10),GetTime,120) &gt;= #{qc.signBeginTime}]] [[and convert(varchar(10),GetTime,120) &lt;= #{qc.signEndTime}]] " +
            "[[and convert(varchar(10),BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),BackLimit,120) &lt;= #{qc.endTime}]] " +
            "[[and SDeptName = #{qc.sdeptName}]]")
    List<Map<String, Object>> listSonWaitJson1_gxq(@Param("qc") QueryConditionVo qc);

    /**
     * 加载派单管理列表数据
     *
     * @param sendBack 查询条件
     * @param deptId   部门编号
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,SeqName,SortName,DealName,SBDeptName,SendDesc,SDeptName," +
            "convert(varchar(19),BackLimit,20) as backLimit,SUserName,convert(varchar(19),SendTime,20) as sendTime," +
            "SendState as chgState,convert(varchar(19),GetTime,20) as getTime,GetPerson,BUserName,BackState,isGoBack," +
            "convert(varchar(19),BackTime,20) as backTime from mWfSendBack " +
            "where WfId=#{param1.wfId} and SDeptID=#{param2} and IsDel=0 " +
            "[[and SBDeptName = #{param1.sbdeptName}]] [[and SortName = #{param1.sortName}]]")
    List<Map<String, Object>> sendBackListJson(MwfSendBack sendBack, Long deptId);


    /**
     * 检查二级部门下派的派单记录是否有下级回复
     *
     * @param wfId    工单id
     * @param sdeptId 拟派部门编号
     * @return 已回复/''
     */
    @Select("SELECT PkId,BackDesc FROM mWfSendBack where IsDel=0 and SendState not in (40) and wfId=#{param1} AND sdeptId=#{param2}")
    List<CheckSendBack> checkSendBack(Integer wfId, String sdeptId);

    /**
     * 查找下级部门办理件 取每个部门最新的回复
     *
     * @param wfId    工单id
     * @param sdeptId 部门编号
     * @return 派单列表
     */
    @Select("SELECT PkId,SeqName,SortName,SBDeptId,SBDeptName,BDutyDept,BUserName,BDutyTel,convert(varchar(19),BackTime,20) as backTime,BackDesc,BackState From mWfSendBack" +
            " where IsDel = 0 and SendState not in(30,40) and wfId = #{wfId} and sdeptId = #{sdeptId}" +
            " and PkId in(select max(PKID) from mWfSendBack where IsDel = 0 AND SendState NOT IN ( 30, 40)" +
            " AND wfId = #{wfId} AND sdeptId = #{sdeptId} GROUP BY SBDeptID) order by BackTime desc")
    List<MwfSendBack> listSendDeptSon(@Param("wfId") Integer wfId, @Param("sdeptId") Long sdeptId);

    /**
     * 查找下级部门办理件 取每个部门最新的回复
     *
     * @param wfId    工单id
     * @param sdeptId 部门编号
     * @return 派单列表
     */
    @Select("SELECT PkId,SeqName,SortName,SBDeptId,SBDeptName,BDutyDept,BUserName,BDutyTel,convert(varchar(19),BackTime,20) as backTime,BackDesc,BackState,row_number() over(partition by SBDeptID order by SendTime desc) groupIndex  " +
            " From mWfSendBack where IsDel = 0 and SendState not in(30,40) and wfId = #{wfId} and sdeptId = #{sdeptId}" )
    List<MwfSendBack> findSubDeptHandleWF(@Param("wfId") Integer wfId, @Param("sdeptId") Long sdeptId);

    /**
     * 查找下级部门办理件 使用当前派单id作为pid查询
     *
     * @param sendId  派单id
     * @param sdeptId 部门编号
     * @return 派单列表
     */
    @Select("SELECT PkId,SeqName,SortName,SBDeptName,BDutyDept,BUserName,BDutyTel,convert(varchar(19),BackTime,20) as backTime,BackDesc,BackState From mWfSendBack" +
            " where IsDel = 0 and SendState not in(30,40) and pid = #{sendId} and sdeptId = #{sdeptId}")
    List<MwfSendBack> listSendSubDept(@Param("sendId") Integer sendId, @Param("sdeptId") Long sdeptId);

    /**
     * 查询信件延期申请情况列表
     *
     * @param mwfDeferEty 信件延期查询条件
     * @param deptId      部门编号
     * @return 列表数据
     */
    @Select("select PkId,SendID,WfId,WorkFormNO,ADeptName,convert(varchar(10),LimitOld,20) as tmLimit," +
            "convert(varchar(19),DelayTo,20) as tmDelay,DelayRN,DeferState,convert(varchar(10),CheckTime,20) as tmChk" +
            " from mWfDefer where ADeptNo=#{deptId} and IsDel=0 [[and WorkFormNO = #{defer.workFormNo}]] [[ and ADeptName = #{defer.adeptName}]]")
    List<MwfDeferEty> mDeferResultJson(@Param("defer") MwfDeferEty mwfDeferEty, @Param("deptId")String deptId);

    /**
     * 查询下级退回工单 全退工单
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SBDeptName,SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState,BackState as chgChk " +
            "from mWfSendBack where dbo.frMailSBIsAllBack(WfId,#{deptId}) = 1 and SBDeptID=#{deptId} and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> listAllSonABackJson(HashMap<String, Object> params);

    /**
     * 查询下级退回 待处理工单
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SBDeptName,SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState,BackState as chgChk " +
            "from mWfSendBack where SDeptID=#{deptId} and SendState=40 and FlagInt = 1 and IsDel=0" +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]] " +
            "[[and dbo.frMailWFSpareStr(WfId) =#{spareString}]]")
    List<Map<String, Object>> listSonNABackJson(HashMap<String, Object> params);

    @Select("select PkId as myPkVal,WfId,MailPK,SDeptID as fDNo,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SBDeptName,SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SendRemark,SendState,BackState,BackState as chgChk " +
            "from mWfSendBack where SDeptID=#{deptId} and SendState=40 and FlagInt = 1 and IsDel=0 and DATEDIFF(day, GetDate(), BackLimit) > -15 " +
            "[[and dbo.frMailWFNo(WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]] " +
            "[[and dbo.frMailWFSpareStr(WfId) =#{spareString}]]")
    List<Map<String, Object>> listSonNABackJson_gxq(HashMap<String, Object> params);

    /**
     * 查询下级部门信件的未签收、未回复、退回和超期情况数据统计
     * 2022/12/29
     * @Param deptId 部门编号
     */
//    @Select("select \n" +
//            "SBDeptName as deptName,\n" +
//            "sum(case when SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and IsDel=0 then 1 else 0 end) as subNotSignNum,\n" +
//            "sum(case when SendState in(21,23) and BackState in (0,12,22) and IsDel=0 then 1 else 0 end) as subNotReplyNum,\n" +
//            "sum(case when SendState = '40'  and IsDel=0 then 1 else 0 end) as subBackNum,\n" +
//            "sum(case when SendState in(21,23) and BackState in (0,12,22) and IsDel=0 and DATEDIFF(day, GETDATE(), BackLimit) IN (1,0) then 1 else 0 end) as subBlueNum\n" +
//            "from mWfSendBack\n" +
//            "where  SDeptID=#{deptId} and IsDel =0\n" +
//            "group by SBDeptName")
    @Select("select \n" +
            "   subDept.deptName,\n" +
            "   sum(case when SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and IsDel=0 then 1 else 0 end) as subNotSignNum,\n" +
            "   sum(case when SendState in(21,23) and BackState in (0,12,22) and IsDel=0 then 1 else 0 end) as subNotReplyNum,\n" +
            "   sum(case when SendState = '40'  and IsDel=0 then 1 else 0 end) as subBackNum,\n" +
            "   sum(case when SendState in(21,23) and BackState in (0,12,22) and IsDel=0 and DATEDIFF(day, GETDATE(), BackLimit) IN (1,0) then 1 else 0 end) as subBlueNum\n" +
            " from (SELECT noUnit,deptShort,deptName FROM bUserDept WHERE noParent=#{deptId} AND useState=1 AND isDel=0  ) as subDept\n" +
            " left join mWfSendBack mwsb on mwsb.SBDeptName =subDept.deptName\n" +
            " group by subDept.deptName\n" +
            " order by subDept.deptName")
    List<Map<String,Object>> listSubStatisticsJson(@Param("deptId") Long deptId);

    /**
     * 查询下级部门信件的未签收、未回复、退回和超期情况数据统计 by存储过程ReportMailState实现
     * 2023/2/1
     * @Param deptId 部门编号
     */
    @Select("{call ReportMailState(#{deptId,mode=IN,jdbcType=BIGINT})}")
    List<Map<String,Object>> listSubStatisticsJ(@Param("deptId") Long deptId);

    @Select("{call ReportMailState_gxq(#{deptId,mode=IN,jdbcType=BIGINT})}")
    List<Map<String,Object>> listSubStatisticsJ_gxq(@Param("deptId") Long deptId);

    /**
     * 查询市级已删除列表数据
     * @param deptId 登录用户部门编号
     * @param workFormNo 信件工单编号
     * @param mwfSendBack 信件拟派工单
     * @return 列表数据
     */
//    @Select("select * from (select wfs.PkId as myPkVal,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString,SendState," +
//            " row_number() over(partition by WfId order by sendState desc) rb," +
//            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate," +
//            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId" +
//            " where wfs.SBDeptID=#{deptId} and wfs.IsDel=1 and m.IsDel = 0 and dbo.frMailWFStep(WfId)>399" +
//            " [[and SDeptName =#{mwf.sdeptName}]] [[and m.WorkFormNO=#{workFormNo}]]) as A" +
//            " where rb= 1")
    @Select("select wfs.PkId as myPkVal,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString," +
            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,sendState," +
            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId" +
            " where wfs.SBDeptID=#{deptId} and m.IsDel=1 " +
            " [[and SDeptName =#{mwf.sdeptName}]] [[and m.WorkFormNO=#{workFormNo}]]")
    List<Map<String, Object>> deletedMailWFList(@Param("deptId")String deptId,@Param("workFormNo") String workFormNo,@Param("mwf")MwfSendBack mwfSendBack);

    /**
     * 查询工单被删除次数
     * @param deptId 登录用户部门编号
     * @param workFormNo 信件工单编号
     * @param mwfSendBack 信件拟派工单
     * @return 列表数据
     */
    @Select(" with tabs as(select m.WorkFormNO as myMwfNO,row_number() over(partition by WfId order by sendState desc) rb" +
            " from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId" +
            " where wfs.SBDeptID=#{deptId} and wfs.IsDel=1 and m.IsDel = 0 and dbo.frMailWFStep(WfId)>399" +
            " [[and SDeptName =#{mwf.sdeptName}]] [[and m.WorkFormNO=#{workFormNo}]])"+
            " select max(rb) as sendOrderNum,myMwfNO from tabs group by myMwfNO")
    List<Map<String, Object>> sendOrderNums(@Param("deptId")String deptId,@Param("workFormNo") String workFormNo,@Param("mwf")MwfSendBack mwfSendBack);

    /**
     * 催办派单
     * @param sbId 派单id
     * @return
     */
    @Update("update mWfSendBack set isUrge = 1  where PkId = #{sbId}")
    int updateUrgeTransact(@Param("sbId") String sbId);


    /**
     * 未签收列表 同源派单
     *
     *
     * @param deptNo 登录用户部门编号
     * @param mwfSendBack 信件拟派工单
     * @return 列表数据
     */
    @Select("select wfs.PkId,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString," +
            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate," +
            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId" +
            " where wfs.SBDeptID=#{sbdeptId} and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and wfs.IsDel=0 and m.IsDel=0" +
            " [[and m.FromTopic like '%'+#{mwf.myMwfTopic}+'%']]" +
            " [[and m.FmContent like '%'+#{mwf.fmContent}+'%']]")
    List<Map<String, Object>> notSignListJson(@Param("sbdeptId")String deptNo,@Param("mwf")MwfSendBack mwfSendBack);


    /**
     * 查询待本部门回复列表数据
     *
     * @param deptNo 登录用户部门编号
     * @param mwfSendBack 信件拟派工单
     * @return 列表数据
     */
    @Select(" select m1.PkId,WfId,dbo.frMailWFNo(WfId) as myMwfNO, dbo.frMailWFTopic(WfId) as myMwfTopic," +
            " m2.FmContent,SeqName,SortName,DealName,BackLimit as bkLimit,MailPK," +
            " SDeptName,GetTime as acDate,BackState as bkState,BackRemark as acRemark," +
            " subBackState cbackDesc,m2.SpareString " +
            " from mWfSendBack m1 inner join mMailWorkForm m2 on m1.WfId=m2.PkId" +
            " where m1.SBDeptID = #{sbdeptId} and m1.SendState in(21,23) and m1.BackState in (0,12,22) and m1.IsDel=0 " +
            " [[and m2.FromTopic like '%'+#{mwf.myMwfTopic}+'%']]" +
            " [[and m2.FmContent like '%'+#{mwf.fmContent}+'%']]")
    List<Map<String, Object>> waitReplyListJson(@Param("sbdeptId")String deptNo,@Param("mwf")MwfSendBack mwfSendBack);

    /**
     * 查找当前部门办理件
     * @param wfId    工单id
     * @param handleDeptId 部门编号
     * @return 派单列表
     */
    @Select("SELECT PkId,SeqName,SortName,SBDeptName,BDutyDept,BUserName,BDutyTel,convert(varchar(19),BackTime,20) as backTime,BackDesc,BackState,sdeptName,sdeptId,sbdeptId From mWfSendBack" +
            " where IsDel = 0 and SendState not in(30,40) and wfId = #{wfId} and SBDeptID = #{handleDeptId}" +
            " and PkId in(select max(PKID) from mWfSendBack where IsDel = 0 AND SendState NOT IN ( 30, 40)" +
            " AND wfId = #{wfId} AND SBDeptID = #{handleDeptId} GROUP BY SBDeptID) order by BackTime desc")
    MwfSendBack curDeptHandleSend(@Param("wfId") Integer wfId, @Param("handleDeptId") String handleDeptId);

    /**
     * 查询处理信件工单数据 未签收及退回工单
     * @param mwfSendBack 信件工单
     * @param deptNo 办理部门
     * @return
     */
    @Select(" select wfs.PkId as myPkVal,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString," +
            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,SendState,BackState," +
            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId " +
            " where wfs.SBDeptID = #{sbdeptId} and wfs.SendState in(10,11,40,51) and wfs.IsDel=0 and dbo.frMailWFStep(WfId)>399 and wfs.SendTime &lt;= getdate() and wfs.SendTime &gt;= dateadd(year,-1,getdate())" +
            " [[and SDeptName =#{mail.sdeptName}]] " +
            " [[and m.WorkFormNO=#{mail.myMwfNO}]]")
    List<Map<String, Object>> notHandleMailJson(@Param("sbdeptId") String deptNo, @Param("mail") MwfSendBack mwfSendBack);

    @Select(" select wfs.PkId as myPkVal,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString," +
            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,SendState,BackState," +
            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId " +
            " where wfs.SBDeptID = #{sbdeptId} and wfs.SendState in(10,11,40,51) and wfs.IsDel=0 and dbo.frMailWFStep(WfId)>399 and wfs.SendTime &lt;= getdate() and wfs.SendTime &gt;= dateadd(year,-1,getdate()) and DATEDIFF(day, GETDATE(), BackLimit) > -30 " +
            " [[and SDeptName =#{mail.sdeptName}]] " +
            " [[and m.WorkFormNO=#{mail.myMwfNO}]]")
    List<Map<String, Object>> notHandleMailJson_gxq(@Param("sbdeptId") String deptNo, @Param("mail") MwfSendBack mwfSendBack);

    /**
     * 导出未处理信件工单数据
     * @param deptId 办理部门
     * @return
     */
    @Select(" SELECT t1.PkId pkId,t1.WfId,t2.FmContent,t1.MailPK,t2.WorkFormNO,t2.FromTopic,t2.FromName,t2.FromTel," +
            " t3.SpareString,t3.FmAddress,t3.FromTime,t3.DFmClaName,SBDeptName,BackDesc,BackTime,BackState,BackRemark," +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,4)) dCntAName1, " +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,6)) dCntAName2, " +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,8)) dCntAName3, " +
            " t1.GetTime signTime,SDeptName,SeqName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) AS BackLimit," +
            " case when t1.SendState = 10 then 1 when t1.SendState = 11 then 2 when t1.SendState=40 then 3 when t1.SendState=40 and t1.BackState=21 then 4 when t1.SendState=51 then 5 else -1 end as currentState " +
            " FROM mWfSendBack t1 inner join mMailWorkForm t2 on t1.WfId=t2.PkId left join mMailGetDeal t3 on t2.OriginFK=t3.PkId" +
            " WHERE t1.SBDeptID = #{sbdeptId} and t1.SendState in(10,11,40,51) and t1.IsDel=0 and dbo.frMailWFStep(WfId)>399 and t1.SendTime <= getdate() and t1.SendTime >= dateadd(year,-1,getdate())")
    List<NotHandleMailExcel> notHandleMailExport(String deptId);

    /**
     * 上级催办信件工单数据
     * @param deptId 办理部门
     * @param mwfSendBack 信件派单
     * @return
     */
    @Select(" select wfs.PkId as myPkVal,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString," +
            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,SendState,BackState," +
            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId " +
            " where wfs.isUrge=1 and wfs.SBDeptID = #{sbdeptId} and wfs.SendState in (10,21,22,23) and wfs.BackState in (0,10,12) and wfs.IsDel=0 and dbo.frMailWFStep(WfId)>399" +
            " [[and SDeptName =#{mail.sdeptName}]] " +
            " [[and m.WorkFormNO=#{mail.myMwfNO}]]")
    List<Map<String, Object>> supUrgeMailOrderJson(@Param("sbdeptId") String deptId,@Param("mail") MwfSendBack mwfSendBack);

    /**
     * 导出上级催办信件工单数据
     * @param deptId 办理部门
     * @return
     */
    @Select(" SELECT t1.PkId pkId,t1.WfId,t2.FmContent,t1.MailPK,t2.WorkFormNO,t2.FromTopic,t2.FromName,t2.FromTel," +
            " t3.SpareString,t3.FmAddress,t3.FromTime,t3.DFmClaName,SBDeptName,BackDesc,BackTime,BackState,BackRemark,SendState," +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,4)) dCntAName1, " +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,6)) dCntAName2, " +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,8)) dCntAName3, " +
            " t1.GetTime signTime,SDeptName,SeqName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) AS BackLimit " +
            " FROM mWfSendBack t1 inner join mMailWorkForm t2 on t1.WfId=t2.PkId left join mMailGetDeal t3 on t2.OriginFK=t3.PkId" +
            " WHERE t1.isUrge=1 and t1.SBDeptID = #{deptId} and t1.SendState in (10,21,22,23) and t1.BackState in (0,10,12) and t1.IsDel=0 and dbo.frMailWFStep(WfId)>399 ")
    List<SupUrgeMailExcel> supUrgeMailOrderExport(String deptId);

    @Select("select wfs.PkId,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString," +
            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate," +
            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId" +
            " where wfs.SBDeptID=#{subDeptId} and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and wfs.IsDel=0 and m.IsDel=0" +
            " [[and SDeptName =#{mail.sdeptName}]] [[and m.WorkFormNO=#{mail.myMwfNO}]]")
    List<Map<String, Object>> subDeptMailDetailJson(@Param("subDeptId")String subDeptId, @Param("mail")MwfSendBack mwfSendBack);


    @Select("select wfs.PkId,WfId,MailPK,m.WorkFormNO as myMwfNO,m.FromTopic as myMwfTopic,m.FmContent,m.SpareString," +
            " SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate," +
            " SendRemark from mWfSendBack wfs inner join mMailWorkForm m on wfs.WfId=m.PkId" +
            " where wfs.SBDeptID=#{subDeptId} and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and wfs.IsDel=0 and m.IsDel=0 and DATEDIFF(day, GETDATE(), wfs.BackLimit) > -30" +
            " [[and SDeptName =#{mail.sdeptName}]] [[and m.WorkFormNO=#{mail.myMwfNO}]]")
    List<Map<String, Object>> subDeptMailDetailJson_gxq(@Param("subDeptId")String subDeptId, @Param("mail")MwfSendBack mwfSendBack);

    /**
     * 未回复工单数量
     * @param deptId 部门编号
     * @return 总数
     */
    // @Select("select count(1) from mWfSendBack t1 left join mMailWorkForm t2 on t1.WfId = t2.PkId and t1.IsDel = 0 and t2.IsDel = 0 " +
    //         "left join tm_mWfSendBack_temp t3 on t1.PkId = t3.sbId " +
    //         "where t1.SBDeptID=#{sbdeptId} and t1.BackState=10 and t3.sbId is null and convert(varchar(10), t1.SendTime,120) > '2023-01-01 00:00:00' ")
    @Select("MwfSendBackSql#countReplyChkJson")
    @Lang(GroovyLangDriver.class)
    Integer countReplyChkJson(Long deptId);

    /**
     * 获取待本级回复的列表
     * @param num 获取条数
     * @param sbdeptId 办理部门编号
     * @return 数据集
     */
    @Select("select top (#{num}) t1.PkId,WfId,OriLevel,SDeptID,SBDeptID,SeqName,SortName,DealName,SDeptName,BackLimit,SBDeptName,BackState " +
            "from mWfSendBack t1 left join mMailWorkForm t2 on t1.WfId = t2.PkId and t1.IsDel = 0 and t2.IsDel = 0 " +
            "left join tm_mWfSendBack_temp t3 on t1.PkId = t3.sbId " +
            "where t1.SBDeptID=#{sbdeptId} and t1.BackState=10 and t3.sbId is null and DATEDIFF(day,GetDate(),t1.BackLimit) > -30  order by SendTime desc ")
    List<MwfSendBack> getAWaitPeerReplyList(@Param("num") Integer num, @Param("sbdeptId") String sbdeptId);

    // /**
    //  * 审核本部门回复列表数据
    //  * 高新区
    //  * @param deptId 当前登录用户部门编号
    //  * @param queryConditionVo 查询参数
    //  * @return列表数据
    //  */
    // @Select("select m1.PkId as PkId,m1.PkId as myPkVal,WfId,MailPK,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,m2.WorkFormNO as myMwfNO,m2.FromTopic as myMwfTopic,SDeptName,SeqName,SortName,DealName,SBDeptName,convert(varchar(10),BackLimit,20) as bkLimit,SBDeptName,convert(varchar(10),BackTime,20) as bkDate,BackState as chgBack,m2.SpareString as SpareString " +
    //         " from mWfSendBack m1 left join mMailWorkForm m2 on m1.WfId = m2.PkId and m1.IsDel = 0 and m2.IsDel = 0 " +
    //         " left join tm_mWfSendBack_temp m3 on m1.PkId = m3.sbId " +
    //         " where m1.SBDeptID=#{deptId} and m1.BackState=10 and m3.sbId is null and convert(varchar(10),m1.SendTime,120) > '2023-01-01 00:00:00' " +
    //         " [[AND m2.WorkFormNO = #{qc.workFormNO}]] " +
    //         " [[AND m2.SDeptName =#{qc.sdeptName}]] " +
    //         " [[AND m2.SUserName =#{qc.opUserName}]] ")
    // List<Map<String, Object>> replyChkJsonData(@Param("deptId") String deptId, @Param("qc") QueryConditionVo queryConditionVo);

    @Select("MwfSendBackSql#replyChkJsonData")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> replyChkJsonData(Map parameter);

    /**
     * 本部门已办毕列表数据
     * 高新区
     * @param deptId 当前登录用户部门编号
     * @param queryConditionVo 查询参数
     * @return列表数据
     */
    @Select("select PkId as myPkVal,WfId,MailPK,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,(select FmContent from mMailWorkForm where PkId=WfId) as FmContent,SDeptName,SeqName,SBDeptName,SortName," +
            "DealName,convert(varchar(10),BackLimit,20) as bkLimit,convert(varchar(10),BackTime,20) as bkDate," +
            "BackState as chgBack,BackRemark,PkId as opDeal from mWfSendBack where SBDeptID=#{deptId} " +
            "and BackState in (11,21) and IsDel=0"+
            "[[AND dbo.frMailWFNo(WfId) = #{qc.workFormNO}]] [[AND SDeptName =#{qc.sdeptName}]] [[AND SUserName =#{qc.opUserName}]]")
    List<Map<String, Object>> repleOverJsonData(@Param("deptId") String deptId, @Param("qc") QueryConditionVo queryConditionVo);

    /**
     * 获取审核本部门回复列表数据
     * 高新区
     * @param deptId 当前登录用户部门编号
     * @param queryConditionVo 查询参数
     * @return列表数据
     */
    @Select("select m2.PkId as PkId,m2.PkId as myPkVal,WfId,MailPK,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,m3.WorkFormNO as myMwfNO,m3.FromTopic as myMwfTopic,SDeptName,SeqName,SortName,DealName,SBDeptName,convert(varchar(10),BackLimit,20) as bkLimit,SBDeptName,convert(varchar(10),BackTime,20) as bkDate,BackState as chgBack,m3.SpareString as SpareString " +
            " from tm_mWfSendBack_temp m1 " +
            " left join mWfSendBack m2 on m1.sbId = m2.PkId and m2.IsDel = 0 " +
            " left join mMailWorkForm m3 on m2.WfId = m3.PkId and m3.IsDel = 0 " +
            " where m1.userNo= #{userId} and m2.SBDeptID=#{deptId} and m2.BackState=10 " +
            " [[AND m3.WorkFormNO = #{qc.workFormNO}]] " +
            " [[AND SDeptName =#{qc.sdeptName}]] " +
            " [[AND SUserName =#{qc.opUserName}]] ")
    List<Map<String, Object>> getReplyChkJson(@Param("userId") Long userId, @Param("deptId") Long deptId, @Param("qc")QueryConditionVo queryConditionVo);

    @Select("select PkId as myPkVal,WfId,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFTopic(WfId) as myMwfTopic," +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName," +
            "(select k.SpareString from mMailWorkForm k where k.PkId=WfId) SpareString," +
            "convert(varchar(10),SendTime,20) sdDate,convert(varchar(10),GetTime,20) as bkDate,BackRemark from mWfSendBack " +
            "where SBDeptID=#{deptId} and SendState = 50 and IsDel=0" +
            "[[and dbo.frMailWFNo(WfId) = #{qc.workFormNO}]] [[and SDeptName =#{qc.sdeptName}]]")
    List<Map<String, Object>> backPeerDeptAuditMJson(@Param("deptId") Long deptId,@Param("qc") QueryConditionVo queryConditionVo);

    @Select("MwfSendBackSql#backPeerDeptAuditMJson_gxq")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> backPeerDeptAuditMJson_gxq(Map parameter);

    @Select("select PkId as myPkVal,WfId,MailPK,dbo.frMailWFNo(WfId) as myMwfNO,dbo.frMailWFSpareStr(WfId) as SpareString," +
            "dbo.frMailWFTopic(WfId) as myMwfTopic,SeqName,SBDeptName,SortName,SDeptName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,SendRemark" +
            " from mWfSendBack where SBDeptID=#{deptId} and SendState in (60) and dbo.frMailWFStep(WfId)>399 and IsDel=0 " +
            "[[and dbo.frMailWFNo(WfId) = #{qc.workFormNO}]] [[and SDeptName =#{qc.sdeptName}]]")
    List<Map<String, Object>> peerDeptNotPassJson(@Param("deptId") Long deptId,@Param("qc") QueryConditionVo queryConditionVo);

    @Select("MwfSendBackSql#dueWorkOrderCount")
    @Lang(GroovyLangDriver.class)
    int dueWorkOrderCount(String deptId);

    /**
     * 查找待本部门回复的工单数据
     * 高新区
     * @param paramMap 参数
     * @return 工单列表数据
     */
    @Select("MwfSendBackSql#replyWaitJson_gxq")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> replyWaitJson_gxq(Map paramMap);

    @Select("DataExportSql#replyWaitJson_gxqExport")
    @Lang(GroovyLangDriver.class)
    List<ReplyWaitMailExcel> replyWaitJson_gxqExport(Map paramMap);
}





